home *** CD-ROM | disk | FTP | other *** search
/ Best of Shareware / Best of PC Windows Shareware 1.0 - Wayzata Technology (7111) (1993).iso / mac / DOS / TELECOMM / PCCP047 / EMUED.C < prev    next >
C/C++ Source or Header  |  1992-08-18  |  9KB  |  314 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  */
  3.  
  4. #include<stdio.h>
  5. #include<fcntl.h>
  6. #include<sys\types.h>
  7. #include<sys\stat.h>
  8. #include<bios.h>
  9. #include<graph.h>
  10. #include"emu.h"
  11.  
  12. main(argc, argv)
  13.     int argc;
  14.     char **argv;
  15.     {
  16.     int emufd, major, minor, scan, value;
  17.     char c, fpname[256];
  18.     _settextposition(25,1);
  19.     printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  20.     printf("You may set the environment variable PCCPPATH.\n");
  21.     printf("If not set we use the current directory.\n\n");
  22.     printf("You should have a copy of emu.h to consult to program display functions.\n\n");
  23.     printf("Making a variable length substitution token last in a\n");
  24.     printf("function sequence is highly questionable.\n\n");
  25.     if(!strcmp(getenv("REMOTE"), "YES"))
  26.         {
  27.         printf("You appear to be logged in remotely, judging by the environment\n");
  28.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  29.         printf("Are you sure you want to run EMUED? (y or n) --> ");
  30.         if(getchar()!='y') /* Note getchar() and not getch()! */
  31.             {
  32.             printf("I didn't think so!\n");
  33.             exit(99);
  34.             }
  35.         else
  36.             printf("OK, you're the boss!\n");
  37.         }
  38.     if(argc!=2)
  39.         {
  40.         printf("USAGE: emued <emu file basename>\n");
  41.         exit(1);
  42.         }
  43.     if(getenv("PCCPPATH")==NULL)
  44.         sprintf(fpname, "%s.emu", argv[1]);
  45.     else
  46.         sprintf(fpname, "%s\\%s.emu", getenv("PCCPPATH"), argv[1]);
  47.     if((emufd=open(fpname, O_RDONLY|O_BINARY))==-1)
  48.         {
  49.         printf("Error opening existing emu file %s for read.\nStarting from scratch.\n\n", fpname);
  50.         nullemu();
  51.         }
  52.     else if(read(emufd, &emu, sizeof(emu))!=sizeof(emu))
  53.         {
  54.         printf("Error reading existing emu file %s.\nStarting from scratch.\n\n", fpname);
  55.         nullemu();
  56.         }
  57.     if(emufd!=-1)
  58.         close(emufd);
  59.     if((emufd=open(fpname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IWRITE))==-1)
  60.         {
  61.         printf("Error opening emu file for write.\n");
  62.         exit(2);
  63.         }
  64.     printf("First column numeric address = %d\n", emu.firstcoladdr);
  65.     printf("First row numeric address = %d\n", emu.firstrowaddr);
  66.     printf("Modify? --> ");
  67.     if(getch()=='y')
  68.         {
  69.         printf("y\nEnter first column numeric address (decimal): --> ");
  70.         scanf("%d", &value);
  71.         emu.firstcoladdr=value;
  72.         printf("Enter first row numeric address (decimal): --> ");
  73.         scanf("%d", &value);
  74.         emu.firstrowaddr=value;
  75.         }
  76.     else
  77.         printf("n\n");
  78.     printf("\ntophi_p = %d {1 => top row is 24; 0 => top is 1}\n", (int)emu.tophi_p);
  79.     printf("Binary row offset = %02x\n", emu.binrowoff);
  80.     printf("Binary column offset = %02x\n", emu.bincoloff);
  81.     printf("default_wrap_p = %d\n", emu.default_wrap_p);
  82.     printf("Modify? --> ");
  83.     if(getch()=='y')
  84.         {
  85.         printf("y\nEnter tophi_p (0 or 1): --> ");
  86.         scanf("%d", &value);
  87.         emu.tophi_p=value;
  88.         printf("Enter binary row offset (hex): --> ");
  89.         scanf("%x", &value);
  90.         emu.binrowoff=value;
  91.         printf("Enter binary column offset (hex): --> ");
  92.         scanf("%x", &value);
  93.         emu.bincoloff=value;
  94.         printf("Enter default_wrap_p (0 or 1): --> ");
  95.         scanf("%d", &value);
  96.         emu.default_wrap_p=value;
  97.         }
  98.     else
  99.         printf("n\n");
  100.     printf("\nBinary attribute zero bitmap offest char = %02x\n", emu.attroffset);
  101.     printf("Bold attribute bitmask = %02x\n", emu.boldmask);
  102.     printf("Faint attribute bitmask = %02x\n", emu.faintmask);
  103.     printf("Blink attribute bitmask = %02x\n", emu.blinkmask);
  104.     printf("Inverse attribute bitmask = %02x\n", emu.inversemask);
  105.     printf("Modify? --> ");
  106.     if(getch()=='y')
  107.         {
  108.         printf("y\nEnter binary attribute zero bitmap offest char (hex): --> ");
  109.         scanf("%x", &value);
  110.         emu.attroffset=value;
  111.         printf("Enter bold attribute bitmask (hex): -- > ");
  112.         scanf("%x", &value);
  113.         emu.boldmask=value;
  114.         printf("Enter faint attribute bitmask (hex): --> ");
  115.         scanf("%x", &value);
  116.         emu.faintmask=value;
  117.         printf("Enter blink attribute bitmask (hex): --> ");
  118.         scanf("%x", &value);
  119.         emu.blinkmask=value;
  120.         printf("Enter inverse attribute bitmask (hex): --> ");
  121.         scanf("%x", &value);
  122.         emu.inversemask=value;
  123.         }
  124.     else
  125.         printf("n\n");
  126.     while(1)
  127.         {
  128.         printf("\n\nk(ey), f(unc), g(raphics char) or e(xit)? --> ");
  129.         c=getch();
  130.         printf("%c\n", c);
  131.         if(c=='k')
  132.             {
  133.             printf("Operate the key --> ");
  134.             while(!_bios_keybrd(_KEYBRD_READY));
  135.             major=_bios_keybrd(_KEYBRD_READ);
  136.             if(major&0xff)
  137.                 printf("\n\007Not a programmable key!\n");
  138.             else
  139.                 {
  140.                 major=(major>>8)&0xff;
  141.                 printf("\nScancode 0x%02x selected.", major);
  142.                 if(emu.keys[major].nullpause_p)
  143.                     printf("  Zero presently means pause 1.1 seconds and ff means break.\n");
  144.                 else
  145.                     printf("  No special translations are in effect.\n");
  146.                 printf("Present contents (blank line means empty):\n");
  147.                 for(minor=0;minor<emu.keys[major].len;++minor)
  148.                     printf(" %02x", emu.keys[major].chars[minor]);
  149.                 printf("\nModify? (y or n): --> ");
  150.                 if(getch()=='y')
  151.                     {
  152.                     printf("y\nZero means 1.1 sec pause and ff means break? (y or n): --> ");
  153.                     if(getch()=='y')
  154.                         {
  155.                         printf("y\n");
  156.                         emu.keys[major].nullpause_p=1;
  157.                         }
  158.                     else
  159.                         {
  160.                         printf("n\n");
  161.                         emu.keys[major].nullpause_p=0;
  162.                         }
  163.                     printf("Enter chars (up to %d). INSERT to enter in hex. END to end:\n-->\n\n", KEYLEN);
  164.                     _settextposition(23,4);
  165.                     minor=0;
  166.                     while(1)
  167.                         {
  168.                         value=_bios_keybrd(_KEYBRD_READ);
  169.                         if(value==0x5200)
  170.                             {
  171.                             printf("\nEnter hex code: --> ");
  172.                             scanf("%x", &value);
  173.                             _settextposition(24,1);
  174.                             printf("\t\t\t\t\t\t\t\t\t\r");
  175.                             }
  176.                         else
  177.                             if(value==0x4f00)
  178.                                 value=END;
  179.                             else
  180.                                 value&=0xff;
  181.                         if(value==END)
  182.                             {
  183.                             printf("\n");
  184.                             emu.keys[major].len=minor;
  185.                             break;
  186.                             }
  187.                         else
  188.                             if(minor<KEYLEN)
  189.                                 {
  190.                                 emu.keys[major].chars[minor++]=value;
  191.                                 _settextposition(23,1);
  192.                                 for(scan=0;scan<minor;scan++)
  193.                                     printf(" %02x", emu.keys[major].chars[scan]);
  194.                                 printf(" -->");
  195.                                 }
  196.                             else
  197.                                 {
  198.                                 printf("\nExcess char ignored.\n");
  199.                                 emu.keys[major].len=KEYLEN;
  200.                                 break;
  201.                                 }
  202.                             }
  203.                     }
  204.                 else
  205.                     printf("n\n");
  206.                 }
  207.             }
  208.         if(c=='f')
  209.             {
  210.             printf("Sequence number (decimal): --> ");
  211.             scanf("%d", &major);
  212.             if((major<0)||(major>=NFUNCS))
  213.                 printf("Bad sequence number.\n");
  214.             else
  215.                 {
  216.                 printf("Function is presently #%d decimal.\n", emu.funcs[major].func);
  217.                 for(minor=0;emu.funcs[major].codes[minor]!=END;++minor)
  218.                     printf(" %03x", emu.funcs[major].codes[minor]);
  219.                 printf("\nModify? (y or n): --> ");
  220.                 if(getch()=='y')
  221.                     {
  222.                     printf("y\nEnter function number in decimal. --> ");
  223.                     scanf("%d", &value);
  224.                     if((value<0)||(value>LASTFUN))
  225.                         printf("Bad function number.\n");
  226.                     else
  227.                         {
  228.                         emu.funcs[major].func=value;
  229.                         printf("Enter chars (up to %d). INSERT to enter in hex. END at end:\n-->\n\n", FUNLEN-1);
  230.                         _settextposition(23,4);
  231.                         minor=0;
  232.                         while(1)
  233.                             {
  234.                             value=_bios_keybrd(_KEYBRD_READ);
  235.                             if(value==0x5200)
  236.                                 {
  237.                                 printf("\nEnter hex code: --> ");
  238.                                 scanf("%x", &value);
  239.                                 _settextposition(24,1);
  240.                                 printf("\t\t\t\t\t\t\t\r");
  241.                                 }
  242.                             else
  243.                                 if(value==0x4f00)
  244.                                     value=END;
  245.                                 else
  246.                                     value&=0xff;
  247.                             emu.funcs[major].codes[minor++]=value;
  248.                             if(value==END)
  249.                                 {
  250.                                 printf("\n");
  251.                                 break;
  252.                                 }
  253.                             else
  254.                                 if(minor<FUNLEN)
  255.                                     {
  256.  
  257.                                     _settextposition(23,1);
  258.                                     for(scan=0;scan<minor;scan++)
  259.                                         printf(" %03x", emu.funcs[major].codes[scan]);
  260.                                     printf(" -->");
  261.                                     }
  262.                                 else
  263.                                     {
  264.                                     minor--;
  265.                                     printf("\nExcess code ignored.\n");
  266.                                     emu.funcs[major].codes[FUNLEN-1]=END;
  267.                                     break;
  268.                                     }
  269.                             }
  270.                         }
  271.                     }
  272.                 else
  273.                     printf("n\n");
  274.                 }
  275.             }
  276.         if(c=='g')
  277.             {
  278.             printf("Enter char or INSERT to enter in hex: --> ");
  279.             value=_bios_keybrd(_KEYBRD_READ);
  280.             if(value==0x5200)
  281.                 {
  282.                 printf("Enter hex: --> ");
  283.                 scanf("%x", &value);
  284.                 }
  285.             else
  286.                 {
  287.                 value&=0xff;
  288.                 printf("%c\n", value);
  289.                 }
  290.             if(emu.gchars[value])
  291.                 printf("Hex code %02x  Current char: -->%c<--  Modify? (y or n) --> ", value, emu.gchars[value]);
  292.             else
  293.                 printf("Hex code %02x  Current char is zero (unspecified).  Modify? (y or n) --> ", value);
  294.             if(getch()=='y')
  295.                 {
  296.                 printf("y\nEnter hex code of new graphics character: --> ");
  297.                 scanf("%x", &emu.gchars[value]);
  298.                 if(emu.gchars[value])
  299.                     printf("gchar %02x hex is now: -->%c<--\n", value, emu.gchars[value]);
  300.                 else
  301.                     printf("gchar %02x hex is now zero (unspecified).\n", value);
  302.                 }
  303.             else
  304.                 printf("n\n");
  305.             }
  306.         if(c=='e')
  307.             break;
  308.         }
  309.     if(write(emufd, &emu, sizeof(emu))!=sizeof(emu))
  310.         printf("Damn!  Couldn't write the file!\n");
  311.     close(emufd);
  312.     exit(0);
  313.     }
  314.